package protobuff.proto;

import com.baidu.bjf.remoting.protobuf.Codec;
import com.baidu.bjf.remoting.protobuf.FieldType;
import com.baidu.bjf.remoting.protobuf.ProtobufProxy;
import com.baidu.bjf.remoting.protobuf.annotation.Protobuf;

/**
 * @author yuzk
 * @date 2018/1/23
 */
public class ProtoSimpleTest {

    @Protobuf(fieldType = FieldType.STRING, order = 1, required = true)
    private String name;

    @Protobuf(fieldType = FieldType.INT32, order = 2, required = false)
    private int value;

    public String getName() {
        return name;
    }

    public ProtoSimpleTest setName(String name) {
        this.name = name;
        return this;
    }

    public int getValue() {
        return value;
    }

    public ProtoSimpleTest setValue(int value) {
        this.value = value;
        return this;
    }

    @Override
    public String toString() {
        return new StringBuffer().append(this.name).append(" : ").append(this.value).toString();
    }

    public static void main(String[] args) {
        Codec<ProtoSimpleTest> simpleTestCodec = ProtobufProxy.create(ProtoSimpleTest.class);
        ProtoSimpleTest pst = new ProtoSimpleTest();
        pst.setName("abc");
        pst.setValue(100);
        try{
            byte[] bb = simpleTestCodec.encode(pst);
            ProtoSimpleTest pst2 = simpleTestCodec.decode(bb);
            System.out.println(pst2);
        }catch (Exception e){
            e.printStackTrace();
        }
    }
}
